/******************************

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
//for setw, precision()
#include <iomanip>
using namespace std;

struct HS{
	char *ten;
	float d1, d2, dtb;

};
void nhap(HS a[]){}
void main(){
	//2a
	HS a[100];
	int n = 0;
	cout << "Nhap so hoc sinh: ";
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cout<<"Nhap thong tinh cho HS thu "<<i+1;
		cout<<"Nhap ten: ";
		gets(a[i].ten);
		cout<<"Nhap diem mon 1, mon 2";
		cin >> a[i].d1 >> a[i].d2;
		a[i].dtb = (a[i].d1 + a[i].d2)/2;

		//2b
		for (int i = 0; i < n-1; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if(a[j].dtb > a[i].dtb){
					char * tTen;
					int tDiem;
					strcpy(tTen, a[i].ten);
					strcpy(a[i].ten, a[j].ten);
					strcpy(a[j].ten, tTen);
					tDiem = a[i].d1;
					a[i].d1 = a[j].d1;
					a[j].d1 = tDiem;

					tDiem = a[i].d2;
					a[i].d2 = a[j].d2;
					a[j].d2 = tDiem;

					tDiem = a[i].dtb;
					a[i].dtb = a[j].dtb;
					a[j].dtb = tDiem;

				}
			}
		}
	}
	//2c - in ra
	int vt = 1;
	int diem = a[0].dtb;
	for (int i = 0; i < n; i++)
	{
		if(a[i].dtb > diem){
			vt++;
			diem = a[i].dtb;
		}
		printf("Hoc sinh %d: ten: %s, d1: %f, d2: %f, dtbinh:%f, vi thu: %d",a[i].ten,a[i].d1,a[i].d2,a[i].dtb,vt);
	}

	//2d

	FILE * f=NULL;
	f= fopen("DULIEU.DAT","wt");
	for (int i = 0; i < n; i++){
		if (a[i].dtb >7)
		{
			// fprintf(fp, "%s %s %s %d", "We", "are", "in", 2012);
			fprintf(f,"%s %f %f %f",a[i].ten,a[i].d1,a[i].d2,a[i].dtb);
		}
	}
	fclose(f);
	{

	}
	getch();
}

/**********************************/